<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of QiNiuUpload
 *
 * @author Administrator
 * 七牛上传流程与本地上传流程不同，所以要重新开一个类实现
 */

namespace frontend\library\upload;

use Qiniu\Auth;

class QiNiuUpload {

    //put your code here
    //put your code here
    protected $bhv;  // 上传行为配置
    protected $store; // 附件存储器
    public $_bucketName;
    public $_accessKey;
    public $_secretKey;

    public function __construct(BaseUploadAction $bhv) {
        $this->bhv = $bhv;
        $this->setStore();
    }

    public final function execute() {
        
    }

    public static function getUploadToken() {

        $auth = new Auth($this->_accessKey, $this->_secretKey);
        $policy = array(
            'callbackUrl' => 'http://172.30.251.210/callback.php',
            'callbackBody' => '{"fname":"$(fname)", "fkey":"$(key)", "desc":"$(x:desc)", "uid":' . $uid . '}'
        );

        return $upToken = $auth->uploadToken($this->_bucketName, null, 3600, $policy);
    }

    public static function callBack() {
        
    }

}
